package com.sbw.springcloud.consumer.feign.demo.controller;

import com.sbw.springcloud.consumer.feign.demo.service.FeignService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.loadbalancer.LoadBalancerClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

/**
 * @Author: sangbowei
 * @Description: TODO
 * @Date: Created in  20:03 2017\12\26 0026
 **/
@RestController
public class FeignController {

    Logger logger = LoggerFactory.getLogger(FeignController.class);


    @Autowired
    FeignService feignService;

    @GetMapping("/feign_discovery_client")
    public String feignDiscoveryClient() {
        String result = feignService.feignDiscoveryClient();
        logger.info(result);
        return result;
    }

    @GetMapping("/feign_hello")
    public String feignHello() {
        String result = feignService.feignHello();
        logger.info(result);
        return result;
    }

    @GetMapping("/feign_hello_delay")
    public String feignHelloDelay() {
        String result = feignService.feignHelloDelay();
        logger.info(result);
        return result;
    }

    @GetMapping("/feign_hello_params")
    public String feignHelloParams(@RequestParam(value = "name") String name) {
        String result = feignService.feignHelloParams(name);
        logger.info(result);
        return result;
    }

    @GetMapping("/feign_hello_client")
    public String feignHelloClient() {
        String result = feignService.feignHelloClient();
        logger.info(result);
        return result;
    }

    @GetMapping("/test_feign_hystrix")
    public void test(){
        for(int i=0;i<1000;i++){
            feignService.feignDiscoveryClient();
        }

        for(int i=0;i<500;i++){
            feignService.feignHello();
        }

        for(int i=0;i<200;i++){
            feignService.feignHelloClient();
        }

        for(int i=0;i<20000;i++){
            feignService.feignHelloParams(i+"");
        }

        for(int i=0;i<300;i++){
            feignService.feignHelloDelay();
        }
    }

}